package com.controller;

import com.domain.Role;
import com.github.pagehelper.PageInfo;
import com.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    //查询全部
    @RequestMapping("/list/{pageNumber}")
    public String selectAllPage(@PathVariable(value = "pageNumber") Integer pageNumber,
                                @RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize, ModelMap map,
                                @RequestParam(value = "valueId", required = false) Integer valueId) {
        PageInfo<Role> pageInfo = roleService.selectRoleAll(pageNumber, pageSize);
        map.put("pageInfo", pageInfo);
        return "roleList";
    }


    @RequestMapping("/addUI")
    public String addUI() {
        return "roleAdd";
    }

    @RequestMapping("/insert")
    public String insert(Role role) {
        roleService.insert(role);
        return "redirect:/role/list/1";
    }
}
